//--------------------------------------------------------------------------------
// This file is a portion of the PracticeEngine Rendering Engine.  It is distributed
// under the MIT License, available in the root of this distribution and 
// at the following URL:
//
// http://www.opensource.org/licenses/mit-license.php
//
// Copyright (c) Ferdinand Li 
//--------------------------------------------------------------------------------
#ifndef ModelLoader_h__
#define ModelLoader_h__

#include "PCH.h"
#include "PEMath.h"
#include "RenderActor.h"
#include <vector>

namespace PracEng
{
	class OBJMaterial
	{
	public:
		OBJMaterial(){};
		~OBJMaterial(){};

		std::string Name;
		std::string map_Ka;
		std::string map_Kd;
		std::string map_bump;
		std::string bump;
		float Ns;	//Specular Exponent
		float Ni;	//optical_density
		float d;	//Specifies the dissolve for the current material
		float Tr;	//
		PEFloat3 Tf;//
		PEFloat3 Ka;
		PEFloat3 Kd;
		PEFloat3 Ks;
		PEFloat3 Ke;
		int illum; // illumination model

	};

	class OBJFaceInfo
	{
	public:
		int VertexIdx;
		int NormalIdx;
		int UVIdx;
		OBJFaceInfo();
		OBJFaceInfo(const OBJFaceInfo& obj);
	};

	class OBJModel
	{
	public:
		OBJModel();
		~OBJModel();

		std::string Name;
		std::string MtlName;
		std::wstring DiffuseMapName;
		std::wstring NormalMapName;
		std::vector<PEFloat3> VertexBuffer;
		std::vector<PEVector3> VertexNormal;
		std::vector<PEVector4> VertexTangent;
		std::vector<PEFloat2> UVs;
		std::vector<OBJFaceInfo> FaceInfos;


	};

	/**
		a helper class to load obj and mtl files, 
		please ref: http://paulbourke.net/dataformats/obj/ & http://paulbourke.net/dataformats/mtl/ (Thx to Paul! ^_^)
	*/
	class OBJModel_Loader
	{
	public:
		OBJModel_Loader();
		~OBJModel_Loader();

		static bool Load(std::wstring& ObjFilePath, std::wstring& MtlFilePath, std::vector<OBJModel* >& Objects);
		static bool BuildTangent(std::vector<OBJModel* >& Objects);
	};

}


#endif // ModelLoader_h__